package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.Merchant;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.admin.MerchantService;
import com.sky.service.user.ShoppingCartService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @Autowired
    private MerchantService merchantService;

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    private Result<List<ShoppingCart>> list(){
        return Result.success(shoppingCartService.showShoppingCart());
    }

    @DeleteMapping("/clean")
    private Result delete(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }

    //  获取店铺电话
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo() {
        //  获取唯一商家对象信息
        Merchant merchant = merchantService.getShopById(1L);
        String shopName = merchant.getShopName();
        String shopAddress = merchant.getShopAddress();
        String shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return Result.success(build);
    }
}
